/*
 * 百度在线网络技术（北京）有限公司拥有本软件版权2021并保留所有权利。
 * Copyright 2021, Baidu.com,Inc 2:Baidu Online Network Technology (Beijing) Co.,Ltd,
 * All rights reserved.
 */

package com.azdebugit.lfu.test;//排序后，count值小的排在最前面，当执行poll时，count值最小的也就会被最先弹出。

import org.checkerframework.checker.units.qual.K;

public class Node implements Comparable<Node> {
    private K key;

    private int count;

    public Node(K key, int count) {
        this.key = key;

        this.count = count;

    }

    public K getKey() {
        return key;

    }

    public int getCount() {
        return count;

    }

    public void setCount(int count) {
        this.count = count;

    }

    @Override

    public String toString() {
        return "[key=" + key + ", count=" + count + "]";

    }

    @Override

    public int compareTo(Node o) {
        return this.count - o.count;

    }

    private static void testLFU() {
        MyLFU map = new MyLFU(10);

        for (int i = 0; i < 20; i++) {
            if (i == 9) {
                map.get("k8");//访问后，元素被移动到队列尾部去了。

            }

            if (i == 6) {
                map.get("k5");

                map.get("k3");

            }

            map.put("k" + i, i);

        }

        for (int i = 0, n = map.queue.size(); i < n; i++) {
            System.out.println(map.queue.poll());

        }
    }
}